<template>
  <div class="app-container ">
    <el-form ref="form" size="mini" :model="form" :rules="rules" label-width="180px">
      <el-tabs v-model="activeName">
        <el-tab-pane style="padding-top:10px" label="提现设置" name="提现设置">
          <el-row>
            <el-col :span="24">
              <el-form-item label="提现方式">
                <el-checkbox-group v-model="form.collect_type">
                  <el-checkbox v-for="(item,i) in select.collect_typearray" :key="i" :label="item.val.toString()">
                    {{ item.key }}
                  </el-checkbox>
                </el-checkbox-group>
                <div class="help-block">微信自动支付，需要申请微信支付的企业付款到零钱功能</div>
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
      <el-form-item>
        <el-button size="mini" type="primary" @click="submit">保存设置</el-button>
      </el-form-item>
    </el-form>

  </div>
</template>
<script>
export default {
  name: 'Configcollect',
  components: {},
  data() {
    return {
      select: {},
      form: {
        collect_type: ['bank']
      },
      loading: false,
      activeName: '提现设置',
      rules: {}
    }
  },
  mounted() {
    this.$api.post('/config/getField').then(res => {
      this.select = res.data
    })
    this.$api.post('/config/getInfo', {
      mo: 'collect'
    }).then(res => {
      this.form = JSON.stringify(res.data) == '[]' ? {} : res.data
      this.setDefaultVal('keyword')
    })
  },
  methods: {
    submit() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.loading = true
          this.$api.post('/config/update', this.form).then(res => {
            this.$message({
              message: '操作成功',
              type: 'success'
            })
          }).catch(() => {
            this.loading = false
          })
        }
      })
    },
    setDefaultVal(key) {
      if (this.form[key] == null || this.form[key] == '') {
        this.form[key] = []
      }
    }
  }
}
</script>
